﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace MossmanMill.DataModel
{
    public class Room
    {
        public int Id { get; private set; }
        public string Name { get; private set; }
        public Point Location { get; private set; }

        private List<Rack> _racks;
        public List<Rack> Racks
        {
            get {
                if (_racks != null) return _racks;
                var db = DatabaseAccess.Instance;
                _racks = db.GetRacks(Id);
                return _racks;
            }
        }

        public Room(int id, string name, string location)
        {
            Id = id;
            Name = name;
            var point = location.Split(',');
            Location = new Point(int.Parse(point[0]), int.Parse(point[1]));
        }

        public override string ToString()
        {
            return Name;
            //var str = "Room ";
            //str += Id;
            //str += ". ";
            //str += Name;
            //str += " [" + Location.X + "," + Location.Y + "]";
            //return str;
        }

        public void SetLocation(Point c)
        {
            Location = c;
        }

        public string LocString()
        {
            return Location.X + "," + Location.Y;
        }

        public void Release()
        {
            _racks = null;
        }
    }
}
